var oUname = document.getElementById("uname")
var oUpass = document.getElementById("upass")
var oUpass2 = document.getElementById("upass2")
var oError = document.getElementById("error_box")
var isError = true;

function fnRegister() {
    if (oUname.value.length > 20 || oUname.value.length < 4) {
        oError.style.display = "block"
        oError.innerHTML = "用户名请输入4-20位字符";
        isError = false;
        return;
    } else if ((oUname.value.charCodeAt(0) >= 48) && (oUname.value.charCodeAt(0) <= 57)) {
        oError.style.display = "block"
        oError.innerHTML = "首字符必须为字母";
        return;
    } else for (var i = 0; i < oUname.value.charCodeAt(i); i++) {
        oError.style.display = "block"
        if ((oUname.value.charCodeAt(i) < 48) || (oUname.value.charCodeAt(i) > 57) && (oUname.value.charCodeAt(i) < 97) || (oUname.value.charCodeAt(i) > 122)) {
            oError.innerHTML = "必须为字母跟数字组成";
            return;
        }
    }
    if (oUpass.value.length > 20 || oUpass.value.length < 4) {
        oError.style.display = "block"
        oError.innerHTML = "密码请输入4-20位字符"
        isError = false;
        return;
    } 

    if(oUpass.value != oUpass2.value) {
        oError.style.display = "block"
        oError.innerHTML = "密码不一致"
        isError = false;
        return;
    }

    oError.style.display = "none";
    window.alert("注册成功");
    window.location.href="index.html";
}

function fnLogin() {
    if(oUname.value !== 'admin' || oUpass.value != 123456) {
        if(oUname.value !== 'admin') {
            oError.style.display = "block"
            oError.innerHTML = "请输入正确的账号！"
            return
        }else if(oUpass.value != 123456) {
            oError.style.display = "block"
            oError.innerHTML = "请输入正确的密码！"
            return
        }else if(oUname.value !== 'admin' && oUpass.value != 123456) {
            oError.style.display = "block"
            oError.innerHTML = "请重新确认账号和密码！"
            return
        }
        return;
    } else {
        window.location.href="index.html";
        return false
    }
}

$('#registerInput').click(function() {
    fnRegister()
    return false
})

$('#loginInput').click(function() {
    fnLogin()
    return false
})



